

clear
set more off
cap log close

***************************************************************************************************
* Program: produce_appendix_tables.do
* Purpose: Generate supplemental tables (Table S1–S15) for the appendix.
***************************************************************************************************

************************************************************************
** set macros (directory)
************************************************************************
global prison_dir "~/Dropbox/Prison_Covid/PNAS_Nexus_Replication"
global raw_data "${prison_dir}/raw_data"
global intermediate_data "${prison_dir}/intermediate_data"
global code "${prison_dir}/code"
global analysis_data "${prison_dir}/analysis_data"
global output "${prison_dir}/output"

* Variables 
global demo "pct_nh_blk_alone_acs_15_19 pct_nh_white_alone_acs_15_19 pct_hisp_latino_acs_15_19 pct_college_acs_15_19 med_hhc_inc_acs_15_19 pct_pop_65plus_acs_15_19 log_tot_pop_acs_15_19"
global cubic "ZCTA_max_cases_p100k_rmpri5 ZCTA_max_cases_p100k_rmpri5_sq ZCTA_max_cases_p100k_rmpri5_cu"

global covidXwhite "cum_cases5_X_pct_white cases_5_X_pct_white cases_sq_5_X_pct_white cases_cu_5_X_pct_white"
global covidXinc "cum_cases5_X_inc cases_5_X_inc cases_sq_5_X_inc cases_cu_5_X_inc"	


*********************************************************************************
* Produce Tables
*********************************************************************************


***************************************************************
* Table S1: Phone Counts by Prison
// Note: The datasets ID_prison_month_hours.dta and ID_home_ZCTA.dta are not included in the replication package due to data privacy concerns. 
// As a result, the code necessary to generate Supplementary Table S1 has been commented out.
***************************************************************

/*
use "ID_prison_month_hours.dta", clear
merge m:1 ID_2020 using "ID_home_ZCTA.dta"

keep if _merge == 3

* calculate total # of visitors by month
gegen phones_count = count(ID_2020), by(Shapefile_ID month)

* collapse to prisonXmonth level 
sort Shapefile_ID month
drop if Shapefile_ID == Shapefile_ID[_n-1] & month == month[_n-1]
keep Shapefile_ID month phones_count

* only keep June
keep if month == 6

* get county info for prison
rename Shapefile_ID _ID
merge 1:1 _ID using "${intermediate_data}/cdcr_population_w_ShapefileID.dta", keepusing(COUNTYFIPS NAME) nogenerate
rename _ID Shapefile_ID

* drop non-state prison 
drop if inlist(NAME, "CUESTA CONSERVATION CAMP #24", "DEPARTMENT OF STATE HOSPITALS - ATASCADERO", ///
				"DEPARTMENT OF STATE HOSPITALS - COALINGA", "MCFARLAND FEMALE COMMUNITY REENTRY FACILITY", ///
				"FOLSOM WOMEN'S FACILITY (FWF)")

save "${intermediate_data}/prison_phones_count_June.dta", replace
*/



***************************************************************
* Table S2: Summary Statistics
***************************************************************

use "${analysis_data}/San_Quentin_main_analysis_data.dta", clear 

***************************************
* get weight under different matching schemes * 
***************************************

qui drdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19 if inlist(month, 5, 6), ///
ivar(ZCTA_contact) time(month) tr(treated) dripw
drdid_predict wgt_covid_temp 

qui drdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo if inlist(month, 5, 6), ///
ivar(ZCTA_contact) time(month) tr(treated) dripw
drdid_predict wgt_covid_demo_temp

gegen wgt_covid = max(wgt_covid_temp), by(ZCTA_contact)
gegen wgt_covid_demo = max(wgt_covid_demo_temp), by(ZCTA_contact)

drop *_temp

***************************************
* summary statistics: balance check between treatead vs. control 
***************************************		

* (unweighted)
eststo clear 
eststo treated: quietly estpost summarize ZCTA_max_cases_p100k_rmpri5 cum_max_cases_p100k_rmpri5 $demo ///
if treated == 1 & ~missing(wgt_covid) & month == 5
eststo control: quietly estpost summarize ZCTA_max_cases_p100k_rmpri5 cum_max_cases_p100k_rmpri5 $demo ///
if treated == 0 & ~missing(wgt_covid) & month == 5
eststo diff: quietly estpost ttest ZCTA_max_cases_p100k_rmpri5 cum_max_cases_p100k_rmpri5 $demo ///
if ~missing(wgt_covid) & month == 5, by(treated) unequal

* weighted (COVID-19)
eststo treated_w1: quietly estpost summarize ZCTA_max_cases_p100k_rmpri5 cum_max_cases_p100k_rmpri5  $demo [w = wgt_covid] if treated == 1 & month == 5
eststo control_w1: quietly estpost summarize ZCTA_max_cases_p100k_rmpri5 cum_max_cases_p100k_rmpri5  $demo [w = wgt_covid] if treated == 0 & month == 5

* weighted (COVID-19 + Demographics)
eststo treated_w2: quietly estpost summarize ZCTA_max_cases_p100k_rmpri5 cum_max_cases_p100k_rmpri5  $demo [w = wgt_covid_demo] if treated == 1 & month == 5
eststo control_w2: quietly estpost summarize ZCTA_max_cases_p100k_rmpri5 cum_max_cases_p100k_rmpri5  $demo [w = wgt_covid_demo] if treated == 0 & month == 5

* export to table
esttab treated control diff treated_w1 control_w1 treated_w2 control_w2 ///
using "${output}/tableS2.tex", ///
replace cells("mean(pattern(1 1 0 1 1 1 1)  fmt(2)) sd(pattern(1 1 0 1 1 1 1) fmt(2)) b(star pattern(0 0 1 0 0 0 0) fmt(2)) t(pattern(0 0 1 0 0 0 0) par fmt(2))") ///
label tex ///
mtitles("Treated" "Control" "Diff" "Treated" "Control" "Treated" "Control") ///
mgroups("Unweighted" ///
		"Weighted by COVID-19" "Weighted by COVID-19 \& Demographics", pattern("1 0 0 1 0 1 0") ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))


***************************************************************
* Table S3: Main Specification
***************************************************************

use "${analysis_data}/San_Quentin_main_analysis_data.dta", clear  

estimates clear 
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long	
qui estat event, estore(r1)

csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long		
qui estat event, estore(r2)

csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19, ivar(ZCTA_contact) time(month) gvar(first_treated_lodes) method(dripw) long	
qui estat event, estore(r3)

csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated_lodes) method(dripw) long		
qui estat event, estore(r4)

esttab r* using "${output}/tableS3.tex", ///
replace se  ///
b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)   ///
label booktabs nonotes noobs collabels(none)  ///
mtitles("COVID-19 Variables" "COVID-19 + Demographics" "COVID-19 Variables" "COVID-19 + Demographics") ///
mgroups("Smartphone Measure" "LODES Measure" ///
 , pattern("1 0 1 0") ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 


************************************************************************
* Table S4: Matched on Demographics & COVID X Demographics
************************************************************************

use "${analysis_data}/San_Quentin_main_analysis_data.dta", clear  

estimates clear 
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long		
qui estat event, estore(r1)

csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo $covidXinc, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long	
qui estat event, estore(r2)

csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo $covidXwhite, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long	
qui estat event, estore(r3)

csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo $covidXinc $covidXwhite, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long
qui estat event, estore(r4)

esttab r* using "${output}/tableS4.tex", ///
replace se  ///
b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)   ///
label booktabs nonotes noobs collabels(none)  ///
mtitles("COVID-19 + Demographics" "(1) + COVID-19 X Med Income" "(1) + COVID-19 X \% White" ///
"(1) + COVID-19 X \% White + COVID-19 X Med Income") ///
mgroups("Zip Code New Cases Per 100k" ///
 , pattern("1 0 0 0") ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 



***********************
* Table S5
***********************
use "${analysis_data}/San_Quentin_main_analysis_data.dta", clear
merge m:1 ZCTA_contact using "${intermediate_data}/CVSP_treated_ZCTA.dta"
rename _merge _merge_CVSP
merge m:1 ZCTA_contact using "${intermediate_data}/ASP_treated_ZCTA.dta"
rename _merge _merge_ASP

* get weights in the estimation
qui drdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo if inlist(month, 5, 6), ///
	ivar(ZCTA_contact) time(month) tr(treated) dripw
drdid_predict wgt_covid_demo_temp
gegen wgt_covid_demo = max(wgt_covid_demo_temp), by(ZCTA_contact)


estimates clear 
gunique ZCTA_contact if ~missing(wgt_covid_demo)
local n = "`=r(unique)'"
display "`n'"
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo , ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long
qui estat event, estore(r1)
est restore r1
estadd local N_zcta = "`n'"

gunique ZCTA_contact if ~missing(wgt_covid_demo) & _merge_CVSP == 1
local n = "`=r(unique)'"
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo if _merge_CVSP == 1, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long
qui estat event, estore(r2)
est restore r2
estadd local N_zcta = "`n'"	

gunique ZCTA_contact if ~missing(wgt_covid_demo) & _merge_ASP == 1
local n = "`=r(unique)'"
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo if _merge_ASP == 1, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long
qui estat event, estore(r3)
est restore r3
estadd local N_zcta = "`n'"	

gunique ZCTA_contact if ~missing(wgt_covid_demo) &  _merge_CVSP == 1 & _merge_ASP == 1
local n = "`=r(unique)'"
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo if _merge_CVSP == 1 & _merge_ASP == 1, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long
qui estat event, estore(r4)
est restore r4
estadd local N_zcta = "`n'"	

esttab r* using "${output}/tableS5.tex", ///
 replace se  scalars("N_zcta N. Zip Codes")  ///
 b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)   ///
 label booktabs nonotes noobs collabels(none)  ///
 mtitles("Baseline" "Excl. Zip Codes Connected to CVSP" "Excl. Zip Codes Connected to ASP" "Excl. Zip Codes Connected to ASP + CVSP") ///
 mgroups("Zip Code New Cases Per 100k (Matched on COVID-19 + Demographic Variables)" ///
		 , pattern("1 0 0 0") ///
 prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
	 


***********************
* Table S6
***********************

use "${analysis_data}/San_Quentin_main_analysis_data.dta", clear
merge m:1 ZCTA_contact using "${intermediate_data}/CVSP_treated_ZCTA.dta"
rename _merge _merge_CVSP
merge m:1 ZCTA_contact using "${intermediate_data}/ASP_treated_ZCTA.dta"
rename _merge _merge_ASP

* get weights in the estimation
qui drdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19 if inlist(month, 5, 6), ///
	ivar(ZCTA_contact) time(month) tr(treated) dripw
drdid_predict wgt_covid_temp 
gegen wgt_covid = max(wgt_covid_temp), by(ZCTA_contact)

estimates clear 
gunique ZCTA_contact if ~missing(wgt_covid)
local n = "`=r(unique)'"
display "`n'"
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19 , ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long
qui estat event, estore(r1)
est restore r1
estadd local N_zcta = "`n'"

gunique ZCTA_contact if ~missing(wgt_covid) & _merge_CVSP == 1
local n = "`=r(unique)'"
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19 if _merge_CVSP == 1, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long
qui estat event, estore(r2)
est restore r2
estadd local N_zcta = "`n'"	

gunique ZCTA_contact if ~missing(wgt_covid) & _merge_ASP == 1
local n = "`=r(unique)'"
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19 if _merge_ASP == 1, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long
qui estat event, estore(r3)
est restore r3
estadd local N_zcta = "`n'"	

gunique ZCTA_contact if ~missing(wgt_covid) &  _merge_CVSP == 1 & _merge_ASP == 1
local n = "`=r(unique)'"
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19 if _merge_CVSP == 1 & _merge_ASP == 1, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long
qui estat event, estore(r4)
est restore r4
estadd local N_zcta = "`n'"	

esttab r* using "${output}/tableS6.tex", ///
 replace se  scalars("N_zcta N. Zip Codes")  ///
 b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)   ///
 label booktabs nonotes noobs collabels(none)  ///
 mtitles("Baseline" "Excl. Zip Codes Connected to CVSP" ///
		  "Excl. Zip Codes Connected to ASP" ///
		  "Excl. Zip Codes Connected to ASP + CVSP") ///
 mgroups("Zip Code New Cases Per 100k (Matched on COVID-19 Variables)" ///
		 , pattern("1 0 0 0") ///
 prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 

 
***************************************
** Table S7: Remove Zip Codes with State Prisons
***************************************

use "${analysis_data}/San_Quentin_main_analysis_data.dta", clear  

estimates clear 
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19 if has_state_prison == 0, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long	
qui estat event, estore(r1)

csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo if has_state_prison == 0, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long		
qui estat event, estore(r2)

csdid cum_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19 if has_state_prison == 0, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long
qui estat event, estore(r3)

csdid cum_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo if has_state_prison == 0, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long		
qui estat event, estore(r4)

esttab r* using "${output}/tableS7.tex", ///
replace se  ///
b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)   ///
label booktabs nonotes noobs collabels(none)  ///
mtitles("COVID-19 Variables" "COVID-19 + Demographics" "COVID-19 Variables" "COVID-19 + Demographics") ///
mgroups("Zip Code New Cases Per 100k" "Zip Code Cumulative Cases Per 100k" ///
 , pattern("1 0 1 0") ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 


***************************************
* Table S8: Matched on COVID-19 Variables
***************************************

use "${analysis_data}/San_Quentin_main_analysis_data.dta", clear  

estimates clear 
eststo clear 
forval i = 1/5{
gunique ZCTA_contact if first_treated_`i'HH == 6
local HH`i' = "`=r(unique)'"
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19, ivar(ZCTA_contact) time(month) gvar(first_treated_`i'HH) method(dripw) long	
qui estat event, estore(hr_`i')
est restore hr_`i'
estadd local N_zcta = "`HH`i''"			

}
forval i = 10(10)20{
gunique ZCTA_contact if first_treated_`i'HH == 6
local HH`i' = "`=r(unique)'"
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19, ivar(ZCTA_contact) time(month) gvar(first_treated_`i'HH) method(dripw) long	
qui estat event, estore(hr_`i')
est restore hr_`i'
estadd local N_zcta = "`HH`i''"			
}
esttab hr* using "${output}/tableS8.tex", ///
replace se  scalars("N_zcta N. Treated Zip Codes")  ///
b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)   ///
label booktabs nonotes noobs collabels(none)  ///
mtitles("Hr $>$ 0.5" "Hr $>$ 1" "Hr $>$ 1.5" "Hr $>$ 2" "Hr $>$ 2.5" "Hr $>$ 5" "Hr $>$ 10") ///
mgroups("Zip Code New Cases Per 100k (Matched on COVID-19 Variables)", pattern("1 0 0 0 0 0 0") ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 


***************************************
* Table S9: Matched on COVID-19 Variables & Demographics
***************************************

use "${analysis_data}/San_Quentin_main_analysis_data.dta", clear  

estimates clear 
eststo clear 
forval i = 1/5{
gunique ZCTA_contact if first_treated_`i'HH == 6
local HH`i' = "`=r(unique)'"
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated_`i'HH) method(dripw) long	
qui estat event, estore(hr_`i')	
est restore hr_`i'
estadd local N_zcta = "`HH`i''"			
}
forval i = 10(10)20{
gunique ZCTA_contact if first_treated_`i'HH == 6
local HH`i' = "`=r(unique)'"
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated_`i'HH) method(dripw) long	
qui estat event, estore(hr_`i')		
est restore hr_`i'
estadd local N_zcta = "`HH`i''"			

}
esttab hr* using "${output}/tableS9.tex", ///
replace se scalars("N_zcta N. Treated Zip Codes")  ///
b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)   ///
label booktabs nonotes noobs collabels(none)  ///
mtitles("Hr $>$ 0.5" "Hr $>$ 1" "Hr $>$ 1.5" "Hr $>$ 2" "Hr $>$ 2.5" "Hr $>$ 5" "Hr $>$ 10") ///
mgroups("Zip Code New Cases Per 100k (Matched on COVID-19 Variables \& Demographics)", pattern("1 0 0 0 0 0 0") ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 	


************************************************************************
* Table S10: Defining treated group using contact to San Quentin State Prison in March-May 2020 instead of June 2020.
************************************************************************

use "${analysis_data}/San_Quentin_main_analysis_data.dta", clear  

estimates clear 
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19, ivar(ZCTA_contact) time(month) gvar(first_treated_pre) method(dripw) long		
qui estat event, estore(r1)

csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated_pre) method(dripw) long	
qui estat event, estore(r2)

csdid cum_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19, ivar(ZCTA_contact) time(month) gvar(first_treated_pre) method(dripw)	long	
qui estat event, estore(r3)

csdid cum_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated_pre) method(dripw) long 
qui estat event, estore(r4)

esttab r* using "${output}/tableS10.tex", ///
replace se  ///
b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)   ///
label booktabs nonotes noobs collabels(none)  ///
mtitles("COVID-19 Variables" "COVID-19 + Demographics" "COVID-19 Variables" "COVID-19 + Demographics") ///
mgroups("Zip Code New Cases Per 100k" "Zip Code Cumulative Cases Per 100k" ///
 , pattern("1 0 1 0") ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 


************************************************************************
* Table S11: different estimators: Matched on COVID-19 Variables only
************************************************************************

use "${analysis_data}/San_Quentin_main_analysis_data.dta", clear  

estimates clear 
local method "drimp dripw reg ipw stdipw"
foreach m of local method{
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19, ivar(ZCTA_contact) time(month) gvar(first_treated) method(`m') long	
qui estat event, estore(m`m')
}

esttab m* using "${output}/tableS11.tex", ///
replace se  ///
b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)   ///
label booktabs nonotes noobs collabels(none)  ///
mtitles("drimp" "dripw" "reg" "ipw" "stdipw") ///
mgroups("DV: Zip Code New Cases Per 100k, Matched on COVID-19 Variables" ///
 , pattern("1 0 0 0 0") ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

************************************************************************
* Table S12: different estimators: Matched on COVID-19 + Demographic Variables
************************************************************************

use "${analysis_data}/San_Quentin_main_analysis_data.dta", clear  

estimates clear 
local method "drimp dripw reg ipw stdipw"
foreach m of local method{
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated) method(`m') long	
qui estat event, estore(m`m')
}
 
esttab m* using "${output}/tableS12.tex", ///
replace se  ///
b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)   ///
label booktabs nonotes noobs collabels(none)  ///
mtitles("drimp" "dripw" "reg" "ipw" "stdipw") ///
mgroups("DV: Zip Code New Cases Per 100k, Matched on COVID-19 + Demographics" ///
 , pattern("1 0 0 0 0") ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

	 
***************************************************************
* Table S13:
***************************************************************

use "${analysis_data}/San_Quentin_alternative_home_analysis_data", clear

estimates clear 
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long	
qui estat event, estore(r1)

csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long		
qui estat event, estore(r2)

csdid cum_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long
qui estat event, estore(r3)

csdid cum_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long		
qui estat event, estore(r4)

esttab r* using "${output}/tableS13.tex", ///
 replace se  ///
 b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)   ///
 label booktabs nonotes noobs collabels(none)  ///
 mtitles("COVID-19 Variables" "COVID-19 + Demographics" "COVID-19 Variables" "COVID-19 + Demographics") ///
 mgroups("Zip Code New Cases Per 100k" "Zip Code Cumulative Cases Per 100k" ///
		 , pattern("1 0 1 0") ///
 prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
	 
	
	
***************************************************************
* Table S14:
***************************************************************

use "${analysis_data}/San_Quentin_drop_one_ping_analysis_data.dta", clear  
	
estimates clear  
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long	
qui estat event, estore(r1)

csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long		
qui estat event, estore(r2)

csdid cum_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19, ivar(ZCTA_contact) time(month) gvar(first_treated_lodes) method(dripw) long	
qui estat event, estore(r3)

csdid cum_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated_lodes) method(dripw) long		
qui estat event, estore(r4)

esttab r* using "${output}/tableS14.tex", ////
replace se  ///
b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)   ///
label booktabs nonotes noobs collabels(none)  ///
mtitles("COVID-19 Variables" "COVID-19 + Demographics" "COVID-19 Variables" "COVID-19 + Demographics") ///
mgroups("Zip Code New Cases Per 100k" "Zip Code Cumulative Cases Per 100k" ///
 , pattern("1 0 1 0") ///
prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 


*********************************************************************************
* Table S15:
*********************************************************************************

use "${analysis_data}/Corcoran_analysis_data.dta", clear

estimates clear 
csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long	
qui estat event, estore(r1)

csdid ZCTA_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long		
qui estat event, estore(r2)

csdid cum_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 log_tot_pop_acs_15_19, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long
qui estat event, estore(r3)

csdid cum_max_cases_p100k_rmpri $cubic cum_max_cases_p100k_rmpri5 $demo, ivar(ZCTA_contact) time(month) gvar(first_treated) method(dripw) long		
qui estat event, estore(r4)

esttab r* using "${output}/tableS15.tex", ///
 replace se  ///
 b(3) se(3) star(* 0.10 ** 0.05 *** 0.01)   ///
 label booktabs nonotes noobs collabels(none)  ///
 mtitles("COVID-19 Variables" "COVID-19 + Demographics" "COVID-19 Variables" "COVID-19 + Demographics") ///
 mgroups("Zip Code New Cases Per 100k" "Zip Code Cumulative Cases Per 100k" ///
		 , pattern("1 0 1 0") ///
 prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
 
 
			 
			 